package cn.liangjintang.foldbrowerbundle;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class FileListAdapter extends BaseAdapter {
	private LayoutInflater mInflater;// 得到一个LayoutInfalter对象用来导入布局
	public List<File> files;
	Context context;
	final static String TAG = "FileListAdapter";

	public FileListAdapter(Context context) {
		files = new ArrayList<File>();
		this.context = context;
		this.mInflater = LayoutInflater.from(context);
	}

	public void setData(List<File> files) {
		this.files.clear();
		for (int i = 0; i < files.size(); i++) {
			this.files.add(files.get(i));
		}
		files = null;
		this.notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		return files.size();
	}

	@Override
	public Object getItem(int position) {
		return files.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {

			convertView = mInflater.inflate(R.layout.foldbrowerbundle_listitem,
					null);

			holder = new ViewHolder();

			holder.tv = (TextView) convertView.findViewById(R.id.listitem_tv);
			//Log.e(TAG, "R" + R.id.listitem_tv);
			convertView.setTag(holder);// 绑定ViewHolder对象

		}

		else {

			holder = (ViewHolder) convertView.getTag();// 取出ViewHolder对象

		}
		String string = position == 0 ? "上一级" : files.get(position).getName();
		//System.err.print(string);
		holder.tv.setText(string);
		return convertView;

	}

	private final class ViewHolder {

		public TextView tv;

	}

}
